# -*- coding: utf-8 -*-
"""
@Time    : 2024/7/10 13:49 
@Author  : ZhangShenao 
@File    : decorator_nesting.py 
@Desc    : 装饰器的嵌套

当多个装饰器嵌套时,实际是按照装饰器在函数上声明的顺序,从上到下依次执行
"""


def decorator1(f):
    """装饰器1"""

    def wrapper(*args, **kwargs):
        print("decorator1")
        return f(*args, **kwargs)

    return wrapper


def decorator2(f):
    """装饰器2"""

    def wrapper(*args, **kwargs):
        print("decorator2")
        return f(*args, **kwargs)

    return wrapper


# 装饰器的嵌套
@decorator1
@decorator2
def greeting(name: str):
    print(f"Hello, {name}!")


greeting('zsa')  # 输出：decorator1 -> decorator2 -> Hello, world!
